package com.groupscore.score.service;


import com.groupscore.score.dao.LotterDao;
import com.groupscore.score.pojo.Lotter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;


@Service
public class LotterService {

    @Autowired
    private LotterDao lotterDao;


    public List<Map> findSearchPerson() {

        //1.先出随机小组
        List<Map> groupList = lotterDao.randGroup();
        //2.遍历小组,根据小组id随机查询小组成员
        List<Map> groupListnew = new ArrayList<>();

        groupList.forEach(group -> {
            group.forEach((k, v) -> {
                if(k.equals("group_id")){
                    Map m = lotterDao.randGroupMember(v + "");
                    //group.put("nickname",m.get("nickname"));

                    Map mnew = new HashMap();
                    mnew.putAll(m);
                    groupListnew.add(mnew);
                }
            });
        });
        return groupListnew;
    }

    /**
     * 单抽
     */
    public Map findSearchSingle(){
        return lotterDao.randMember();
    }

    /**
     * 确定后修改状态
     */
    public void updateMember(String id){
        lotterDao.updateMember(id);
    }
}
